package torres.controller;

import java.io.File;
import java.util.HashMap;
import java.util.Scanner;

import javax.swing.KeyStroke;

public class Configuration {
	
	private HashMap<String, Integer> userKeys;
	
	public Configuration() {
		
		userKeys = new HashMap<String, Integer>();
	}
	
	public int getKeyCode(String key) {
		
		key = key.toUpperCase();
		
		if(userKeys.containsKey(key)) {
			
			return userKeys.get(key);
		}
		else {
			
			return KeyStroke.getKeyStroke(key).getKeyCode();
		}
	}
	
	public void loadConfiguration(File file) {
		
		Scanner reader = null;
		
		try {
			
			reader = new Scanner(file);
			
			while(reader.hasNext()) {
				
				String keyName = reader.next();
				reader.next();
				
				String key = reader.next();
				
				int keyCode = KeyStroke.getKeyStroke(key).getKeyCode();
				
				userKeys.put(keyName, keyCode);
			}
		}
		catch(Exception e) {
			
			e.printStackTrace();
		}
		finally {
			
			reader.close();
		}
	}
	
	public String toString() {
		
		return "";
	}
}
